

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>The server module &mdash; pyamp v1.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="pyamp v1.2 documentation" href="../index.html" />
    <link rel="up" title="The http module" href="mod_pyamp_web_http.html" />
    <link rel="next" title="The requests module" href="pyamp_web_http_requests.html" />
    <link rel="prev" title="The errorPages module" href="pyamp_web_http_errorPages.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="pyamp_web_http_requests.html" title="The requests module"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="pyamp_web_http_errorPages.html" title="The errorPages module"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">pyamp v1.2 documentation</a> &raquo;</li>
          <li><a href="mod_pyamp.html" >The pyamp module</a> &raquo;</li>
          <li><a href="mod_pyamp_web.html" >The web module</a> &raquo;</li>
          <li><a href="mod_pyamp_web_http.html" accesskey="U">The http module</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-pyamp.web.http.server">
<span id="the-server-module"></span><h1>The server module<a class="headerlink" href="#module-pyamp.web.http.server" title="Permalink to this headline">¶</a></h1>
<p>The server module contains various classes pertaining to
creating HTTP servers.</p>
<div class="section" id="the-argument-class">
<h2>The Argument class<a class="headerlink" href="#the-argument-class" title="Permalink to this headline">¶</a></h2>
<p class="graphviz">
<img src="../_images/inheritance-2c1ab81224a077a702393d6ba38aab034915b868.png" alt="Inheritance diagram of pyamp.web.http.server.Argument" usemap="#inheritance8b52945afc" class="inheritance"/>
<map id="inheritance8b52945afc" name="inheritance8b52945afc">
<area shape="rect" href="pyamp_web_http_argument.html#pyamp.web.http.argument.Argument" title="pyamp.web.http.argument.Argument" alt="" coords="5,7,264,33"/>
</map>
</p>
<dl class="class">
<dt id="pyamp.web.http.server.Argument">
<em class="property">class </em><tt class="descclassname">pyamp.web.http.server.</tt><tt class="descname">Argument</tt><big>(</big><em>argumentType</em>, <em>required=False</em>, <em>default=None</em><big>)</big><a class="headerlink" href="#pyamp.web.http.server.Argument" title="Permalink to this definition">¶</a></dt>
<dd><p>The Argument class encapsulates the concept of an HTTP argument
passed through a URL request.</p>
<p>Arguments can have a specific type, can be required or optional,
and can have a default value if they are optional and not passed in
the request.</p>
<ul class="simple">
<li>argumentType &#8211; The type of the argument</li>
<li>required &#8211; True if the argument is required, False otherwise</li>
<li>default &#8211; The default value for optional Arguments</li>
</ul>
<dl class="method">
<dt id="pyamp.web.http.server.Argument.convertValue">
<tt class="descname">convertValue</tt><big>(</big><em>value</em><big>)</big><a class="headerlink" href="#pyamp.web.http.server.Argument.convertValue" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the given value to the expected type of the Argument.</p>
<ul class="simple">
<li>value &#8211; The value of the argument passed in the request</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="pyamp.web.http.server.Argument.getDefaultValue">
<tt class="descname">getDefaultValue</tt><big>(</big><big>)</big><a class="headerlink" href="#pyamp.web.http.server.Argument.getDefaultValue" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the default value for this Argument.</p>
</dd></dl>

<dl class="method">
<dt id="pyamp.web.http.server.Argument.isRequired">
<tt class="descname">isRequired</tt><big>(</big><big>)</big><a class="headerlink" href="#pyamp.web.http.server.Argument.isRequired" title="Permalink to this definition">¶</a></dt>
<dd><p>Determine if this is a required Argument or an optional Argument.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="the-httpserverthread-class">
<h2>The HttpServerThread class<a class="headerlink" href="#the-httpserverthread-class" title="Permalink to this headline">¶</a></h2>
<p class="graphviz">
<img src="../_images/inheritance-f5fd2f83a836f08f320b2153c3b6f11f3e0fae87.png" alt="Inheritance diagram of pyamp.web.http.server.HttpServerThread" usemap="#inheritancef520fdc2fc" class="inheritance"/>
<map id="inheritancef520fdc2fc" name="inheritancef520fdc2fc">
<area shape="rect" href="pyamp_logging_loggable.html#pyamp.logging.loggable.Loggable" title="pyamp.logging.loggable.Loggable" alt="" coords="5,84,240,111"/>
<area shape="rect" href="pyamp_processes_threading_thread.html#pyamp.processes.threading.thread.Thread" title="pyamp.processes.threading.thread.Thread" alt="" coords="79,161,372,188"/>
<area shape="rect" href="../web.html#pyamp.web.http.server.HttpServerThread" title="pyamp.web.http.server.HttpServerThread" alt="" coords="83,239,368,265"/>
</map>
</p>
<dl class="class">
<dt id="pyamp.web.http.server.HttpServerThread">
<em class="property">class </em><tt class="descclassname">pyamp.web.http.server.</tt><tt class="descname">HttpServerThread</tt><big>(</big><em>port</em>, <em>requestHandlerClass</em>, <em>host=''</em><big>)</big><a class="reference internal" href="../_modules/pyamp/web/http/server.html#HttpServerThread"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.web.http.server.HttpServerThread" title="Permalink to this definition">¶</a></dt>
<dd><p>The HttpServerThread class provides an implementation of an
HttpServer that runs in its own thread.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">time</span> <span class="kn">import</span> <span class="n">sleep</span>

<span class="kn">from</span> <span class="nn">pyamp.web.http.requests</span> <span class="kn">import</span> <span class="n">StoppableRequestHandler</span>


<span class="n">server</span> <span class="o">=</span> <span class="n">HttpServerThread</span><span class="p">(</span><span class="mi">12345</span><span class="p">,</span> <span class="n">StoppableRequestHandler</span><span class="p">)</span>
<span class="n">server</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>

<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">sleep</span><span class="p">(</span><span class="mf">0.1</span><span class="p">)</span>
    <span class="k">except</span> <span class="p">(</span><span class="ne">KeyboardInterrupt</span><span class="p">,</span> <span class="ne">SystemExit</span><span class="p">):</span>
        <span class="k">print</span> <span class="s">&quot;Stopping server!&quot;</span>
        <span class="n">server</span><span class="o">.</span><span class="n">shutdown</span><span class="p">()</span>
        <span class="k">break</span>

<span class="k">print</span> <span class="s">&quot;Done.&quot;</span>
</pre></div>
</div>
<ul class="simple">
<li>port &#8211; The port for the server</li>
<li>requestHandlerClass &#8211; The class used to handle requests</li>
<li>host &#8211; The host name for the server</li>
</ul>
<dl class="method">
<dt id="pyamp.web.http.server.HttpServerThread.onCycle">
<tt class="descname">onCycle</tt><big>(</big><em>_i</em><big>)</big><a class="headerlink" href="#pyamp.web.http.server.HttpServerThread.onCycle" title="Permalink to this definition">¶</a></dt>
<dd><p>Called once during every cycle of the thread.</p>
<ul class="simple">
<li>_i &#8211; The current cycle number</li>
</ul>
</dd></dl>

<dl class="method">
<dt id="pyamp.web.http.server.HttpServerThread.onShutdown">
<tt class="descname">onShutdown</tt><big>(</big><big>)</big><a class="reference internal" href="../_modules/pyamp/web/http/server.html#HttpServerThread.onShutdown"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.web.http.server.HttpServerThread.onShutdown" title="Permalink to this definition">¶</a></dt>
<dd><p>Called in the event that the Thread is shut down.</p>
</dd></dl>

<dl class="method">
<dt id="pyamp.web.http.server.HttpServerThread.onStop">
<tt class="descname">onStop</tt><big>(</big><big>)</big><a class="reference internal" href="../_modules/pyamp/web/http/server.html#HttpServerThread.onStop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.web.http.server.HttpServerThread.onStop" title="Permalink to this definition">¶</a></dt>
<dd><p>Called in the event that the Thread is stopped.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="the-httpserver-class">
<h2>The HttpServer class<a class="headerlink" href="#the-httpserver-class" title="Permalink to this headline">¶</a></h2>
<p class="graphviz">
<img src="../_images/inheritance-c9b10b1ed9a3677aab6178256827c84b8ff1597e.png" alt="Inheritance diagram of pyamp.web.http.server.HttpServer" usemap="#inheritancec58b6890fc" class="inheritance"/>
<map id="inheritancec58b6890fc" name="inheritancec58b6890fc">
<area shape="rect" href="../web.html#pyamp.web.http.server.HttpServer" title="pyamp.web.http.server.HttpServer" alt="" coords="5,239,245,265"/>
</map>
</p>
<dl class="class">
<dt id="pyamp.web.http.server.HttpServer">
<em class="property">class </em><tt class="descclassname">pyamp.web.http.server.</tt><tt class="descname">HttpServer</tt><big>(</big><em>port</em>, <em>requestHandlerClass</em>, <em>host=''</em><big>)</big><a class="reference internal" href="../_modules/pyamp/web/http/server.html#HttpServer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyamp.web.http.server.HttpServer" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a basic HTTP server.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">BaseHTTPServer</span> <span class="kn">import</span> <span class="n">BaseHTTPRequestHandler</span>


<span class="k">class</span> <span class="nc">RequestHandler</span><span class="p">(</span><span class="n">BaseHTTPRequestHandler</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">do_GET</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        
        <span class="k">print</span> <span class="s">&quot;GET:&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">path</span>

<span class="n">server</span> <span class="o">=</span> <span class="n">HttpServer</span><span class="p">(</span><span class="mi">12345</span><span class="p">,</span> <span class="n">RequestHandler</span><span class="p">)</span>
<span class="n">server</span><span class="o">.</span><span class="n">serve_forever</span><span class="p">()</span>
</pre></div>
</div>
<ul class="simple">
<li>port &#8211; The port for the server</li>
<li>requestHandlerClass &#8211; The class used to handle requests</li>
<li>host &#8211; The host name for the server</li>
</ul>
</dd></dl>

</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">The server module</a><ul>
<li><a class="reference internal" href="#the-argument-class">The Argument class</a></li>
<li><a class="reference internal" href="#the-httpserverthread-class">The HttpServerThread class</a></li>
<li><a class="reference internal" href="#the-httpserver-class">The HttpServer class</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="pyamp_web_http_errorPages.html"
                        title="previous chapter">The errorPages module</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="pyamp_web_http_requests.html"
                        title="next chapter">The requests module</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/_generated/pyamp_web_http_server.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="pyamp_web_http_requests.html" title="The requests module"
             >next</a> |</li>
        <li class="right" >
          <a href="pyamp_web_http_errorPages.html" title="The errorPages module"
             >previous</a> |</li>
        <li><a href="../index.html">pyamp v1.2 documentation</a> &raquo;</li>
          <li><a href="mod_pyamp.html" >The pyamp module</a> &raquo;</li>
          <li><a href="mod_pyamp_web.html" >The web module</a> &raquo;</li>
          <li><a href="mod_pyamp_web_http.html" >The http module</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, Brett Ponsler.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.1.
    </div>
  </body>
</html>